import { Injectable } from '@angular/core';
import { Response } from "@angular/http";
import { Observable } from "rxjs";

import { OrderService } from "@order/order.service";

import { HttpService } from "@core/http/http.service";
import { AuthService } from "@shared/service/auth/auth.service";
import * as API from "@api/index";
import {PAYMENT_PAY_TYPE} from "@core/globals/globals.service";
import {GoodsOrderRespVO, PayInfoRespVO, SNSResult} from "@interface/index";

@Injectable()
export class PaymentService {
  private PAYMENT_INFO_URL = '/payment/info'; // 获取支付相关信息

  constructor(
    private httpService: HttpService,
    private authService: AuthService,
    private orderService: OrderService
  ) { }


  /**
   * @description 获取支付信息
   * @author huangyf1024
   * @date 2017-09-13
   * @param payType  //  支付类型0：支付宝，1：微信, 2:微信公众号
   * @param orderNumber
   * @returns {Observable<R>}
   */
  getPaymentInfo(payType, orderNumber): Observable<SNSResult<PayInfoRespVO>> {
    const userId = this.authService.getUserId(),
      openId = this.authService.getOpenId(),
      array = PAYMENT_PAY_TYPE;
    return this.httpService.get(API.PAYMENT_INFO_URL +
      `?payType=${array[payType]}&userId=${userId}&orderNumber=${orderNumber}&openId=${openId}`)
      .map((res: Response) => res.json());
  }


  /**
   * @description 获取订单详情
   * @author huangyf1024
   * @date 2017-09-13
   * @param orderNumber
   * @returns {Observable<R>}
   */
  getOrderInfo(params: any): Observable<SNSResult<GoodsOrderRespVO>> {
    return this.orderService.getOrderInfo(params);
  }


}
